//
//  clsGhost.cpp
//  NewMath
//
//  Created by Ngô Hoàng Nam on 12/27/14.
//
//

#include "LevelGhostObj.h"
#include "../../../Player/PlayerInfo.h"

#include "../LevelManager.h"
LevelGhostObj::LevelGhostObj()
{
    
}
void LevelGhostObj::initGhost(std::string ghostSprite, std::string text, cocos2d::Vec2 Position, float kScale)
{
    BaseGhostObj::initGhost(ghostSprite, Position, kScale);
   
    m_LeftHand->setVisible(false);
    m_RightHand->setVisible(false);
    m_eye->setVisible(false);
    m_mouth->setVisible(false);
    m_Ghost->setTitleText(text);
    m_Ghost->setTitleFontSize(m_Ghost->getContentSize().height/3*kScale);
    m_Ghost->setTitleColor(Color3B::BLACK);
    
    m_starLeft = Sprite::create("star_normal.png");
    
    
    m_starRight = Sprite::create("star_normal.png");
    m_starTop = Sprite::create("star_normal.png");
    
    m_starLeft->setScale(kScale);
    m_starRight->setScale(kScale);
    m_starTop->setScale(kScale);
    float newWidthGhost = m_Ghost->getContentSize().width*kScale;
    float newHeightGhost = m_Ghost->getContentSize().height*kScale;
    m_starLeft->setPosition(m_Ghost->getPosition().x - newWidthGhost/2 - m_distanceStar_Ghost,m_Ghost->getPosition().y + newHeightGhost/3);
    m_starRight->setPosition(m_Ghost->getPosition().x + newWidthGhost/2 + m_distanceStar_Ghost,m_Ghost->getPosition().y + newHeightGhost/3);
    m_starTop->setPosition(m_Ghost->getPosition().x,m_Ghost->getPosition().y + newHeightGhost/2 + m_distanceStar_Ghost);
    this->addChild(m_starLeft);
    this->addChild(m_starRight);
    this->addChild(m_starTop);
    m_Ghost->addClickEventListener(CC_CALLBACK_1(LevelGhostObj::OpenGameWithLevel, this));

	ID = atoi(text.c_str());
    
}
void LevelGhostObj::OpenGameWithLevel(cocos2d::Ref *pSender)
{
    if(!LevelManager::m_isActive)
    {
		if (!PlayerInfo::getInstance()->level->getLevelEnable(LevelManager::m_ELevelMode, ID))
			return;

        LevelManager::m_isActive = true;
		LevelManager::currID = ID;
        OpenEye();
        OpenMouth();
        OpenHandWithAnimation();
    }
}

void LevelGhostObj::OpenEye()
{
    m_eye->setVisible(true);
}
void LevelGhostObj::OpenMouth()
{
    m_mouth->setVisible(true);
}
void LevelGhostObj::OpenHandWithAnimation()
{
    this->m_LeftHand->setVisible(true);
    this->m_RightHand->setVisible(true);
    this->m_LeftHand->runAction(RepeatForever::create(Sequence::create(RotateBy::create(0.1f, 45),RotateBy::create(0.2f,-45), NULL)));
    this->m_RightHand->runAction(RepeatForever::create(Sequence::create(RotateBy::create(0.1f, -45),RotateBy::create(0.2f,45), NULL)));
    
}